package com.cn.wanxi.servlet.user;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.UserModel;
import com.cn.wanxi.service.UserService;
import com.cn.wanxi.service.impl.UserServiceImpl;
import com.cn.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/user/updateEnable")
public class UserUpdateEnableServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //取值，取得前端页面传递过来的数据

        String idString = req.getParameter("id");
//封装数据
        UserModel userModel = new UserModel();

        userModel.setId(Tool.stringToInt(idString));

//        判断验证码是否输入正确，时属于逻辑关系，应该写在服务逻辑层
//        调用服务逻辑层
        UserService userService = new UserServiceImpl();
//        取得返回结果,如果参数大于两个，且类型一致，都是属于同一个对象--和数据库的表一一对应
        String result = userService.updateEnable(userModel);
//返回数据json对象的格式,如果要用json格式，我们需要加入第三方jar包
        resp.getWriter().println();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        resp.getWriter().println(jsonObject);
    }
}
